home *** CD-ROM | disk | FTP | other *** search
/ Ahoy 1987 August / Ahoy_Magazine_87-08_1987_Double_L_Side_A.d64 / Short Sort 1 (.txt) < prev    next >
Commodore BASIC  |  2022-10-26  |  1KB  |  25 lines

  1. 0 print"[147]":poke53280,12:poke53281,12:poke646,0
  2. 1 rem ==================================
  3. 2 rem    commodares problem #40-2 :
  4. 3 rem       short sort
  5. 4 rem ==================================
  6. 10 for i=1 to 6 : a(i)=int(rnd(0)*1000)-500:print a(i);:qq(i)=a(i):next i:print
  7. 20 for jj=1 to 5 : on jj gosub 110,210,310,410,510
  8. 30 for i=1 to 6 : a(i)=qq(i) : next i : print : next jj
  9. 99 end
  10. 100 rem * solution by jim speers ***********************************************
  11. 110 fori=1to6:k=1:forj=1to6:k=k-(a(j)>a(k))*(j-k):next:printa(k);:a(k)=-9e9:next
  12. 120 return
  13. 200 rem * solution by stephane edwardson****************************************
  14. 210 fory=1to5:forz=yto6:a=a(y):b=a(z):a(y)=-a*(a<=b)-b*(b<a):a(z)=a+b-a(y):nextz,y:forn=1to6:printa(n);:next
  15. 220 return
  16. 300 rem *  solution by ron gow *************************************************
  17. 310 forx=1to6:b=0:fory=1to6:b=b-(a(y)<=a(x)):next:c(b)=a(x):next:forn=1to6:printc(n);:next
  18. 320 return
  19. 400 rem *  solution by d.bruce powell ******************************************
  20. 410 fori=1to5:forj=i+1to6:t=a(j):d=t-a(i):k=d<0:a(j)=t+k*d:a(i)=t-(1+k)*d:nextj:printa(i);:nexti:printa(i);
  21. 420 return
  22. 500 rem *  solution by jeff achtnig  **************** c-128 only ***************
  23. 510 fory=1to6:f=999999999:a(z)=f:forx=1to6:iff>a(x)thenf=a(x):z=x:nextx:printf;:nexty:(NULL)nextx:printf;:nexty
  24. 520 return
  25.